package gowcage.testandroid;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.gowcage.testandroid.R;

import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends Activity {

    @BindView(R.id.main_tv1)
    TextView tv1;
    @BindView(R.id.main_edit1)
    EditText edit1;
    @BindView(R.id.main_btn_round)
    Button btnRound;
    @BindViews({R.id.main_btn1})
    List<Button> btnList;

    final String TAG = "MainActivity-->";
    int targetNum = 0;

    ValueAnimator va;
    ObjectAnimator oa;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    //值动画 int float argb...
    private void startValueAnimator() {
        Log.i(TAG, "targetNum : " + targetNum);
        va = ValueAnimator.ofInt(0, targetNum);
        va.setDuration(10000);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                tv1.setText(Integer.parseInt(valueAnimator.getAnimatedValue().toString()) + "");
            }
        });
        va.start();
    }

    //对象动画
    private void startObjectAnimator(View view) {
        oa = ObjectAnimator.ofFloat(view, "rotationY", 0f, 720f);
        oa.setDuration(4000);
        oa.setInterpolator(new AccelerateDecelerateInterpolator());
        oa.start();
    }

    @OnClick({R.id.main_btn1, R.id.main_btn_round})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.main_btn1:
                if (!TextUtils.isEmpty(edit1.getText())) {
                    targetNum = Integer.parseInt(edit1.getText().toString());
                    startValueAnimator();
                }
                break;
            case R.id.main_btn_round:
                startObjectAnimator(btnRound);
                break;
        }
    }

}
